package com.yifeng.repo.controller.traffic.impl;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.yifeng.repo.base.utils.converter.JacksonHelper;
import com.yifeng.repo.controller.traffic.EndpointService;
import com.yifeng.repo.controller.traffic.in.TrafficIn;
import com.yifeng.repo.controller.traffic.model.ChannelGoodsStockDetailForm;
import com.yifeng.repo.controller.traffic.model.ChannelGoodsStockForm;
import com.yifeng.repo.controller.traffic.model.PlatformEnum;
import com.yifeng.repo.controller.traffic.out.TrafficOut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by daibing on 2019/1/18.
 */
@Service
public class EndpointServiceImpl implements EndpointService {
    private static final Logger logger = LoggerFactory.getLogger(EndpointServiceImpl.class);

    @Override
//    @TrafficOut(factor0Key = "platform", factor1Key = "platformAccountCode", factor2Key = "platformStoreCode")
    @TrafficIn()
    public void pushStock(String batchNo, PlatformEnum platform, String platformAccountCode, String platformStoreCode,
                          String goodsCode, int price) {
        logger.info("pushStock1 start: batchNo {}, platformAccountCode {}, platformStoreCode {}, goodsCode {}, price {}",
                batchNo, platformAccountCode, platformAccountCode, goodsCode, price);

        @TrafficIn ChannelGoodsStockForm form = new ChannelGoodsStockForm();
        logger.info("success1...");

        logger.info("pushStock1 end: batchNo {}, platformAccountCode {}, platformStoreCode {}, goodsCode {}, price {}",
                batchNo, platformAccountCode, platformAccountCode, goodsCode, price);
    }

    @Override
    @TrafficOut(factor0Key = "platform", factor1Key = "platformAccountCode", factor2Key = "platformStoreCode")
    public void pushStock(ChannelGoodsStockDetailForm goodsStockDetail) {
        logger.info("pushStock2 start: goodsStockDetail {}", JacksonHelper.toJson(goodsStockDetail));
        logger.info("success2...");

        logger.info("pushStock2 end: goodsStockDetail {}", JacksonHelper.toJson(goodsStockDetail));
    }

    @Override
    @TrafficOut(factor0Key = "platform", factor1Key = "platformAccountCode", factor2Key = "platformStoreCode")
    public void pushStock(List<ChannelGoodsStockDetailForm> goodsStockDetails) {
        logger.info("pushStock2 start: goodsStockDetails {}", JacksonHelper.toJson(goodsStockDetails));
        logger.info("success2...");
        logger.info("pushStock2 end: goodsStockDetails {}", JacksonHelper.toJson(goodsStockDetails));
    }

    @Override
    @TrafficOut(factor0Key = "platform", factor1Key = "platformAccountCode", factor2Key = "platformStoreCode")
    public String pushGoods(String batchNo, PlatformEnum platform, String platformAccountCode, String platformStoreCode,
                            String goodsCode, int price) {
        logger.info("pushGoods start: batchNo {}, platformAccountCode {}, platformStoreCode {}, goodsCode {}, price {}",
                batchNo, platformAccountCode, platformAccountCode, goodsCode, price);

        logger.info("success3...");

        logger.info("pushGoods end: batchNo {}, platformAccountCode {}, platformStoreCode {}, goodsCode {}, price {}",
                batchNo, platformAccountCode, platformAccountCode, goodsCode, price);
        return "999999";
    }

    @Override
    @TrafficOut(factor0Key = "platform", factor1Key = "platformAccountCode", factor2Key = "platformStoreCode")
    public void pushStock(String batchNo, PlatformEnum platform, String platformAccountCode, String platformStoreCode, List<ChannelGoodsStockDetailForm> forms) {
        logger.info("pushStock999 start: batchNo {}, platformAccountCode {}, platformStoreCode {}, forms {}",
                batchNo, platformAccountCode, platformAccountCode, JacksonHelper.toJson(forms));

        logger.info("success3...");
        List<String> ids = Lists.transform(forms, new Function<ChannelGoodsStockDetailForm, String>() {
            @Override
            public String apply(ChannelGoodsStockDetailForm input) {
                return input.getPlatformAccountCode();
            }
        });

        logger.info("pushStock999 end: batchNo {}, platformAccountCode {}, platformStoreCode {}, forms {}",
                batchNo, platformAccountCode, platformAccountCode, JacksonHelper.toJson(forms));
    }
}
